<?php 
session_start();
$active = 'account';
$set = 'details';
if(!isset($_SESSION['username']) || !isset($_SESSION['id']))
{
	header("Location: index.php");
	exit();
} 
//echo $_SESSION['username'];
require("../db/opendb.php");

$query = "select u.*, s.ID, s.Parent_ID, s.Service from Users u left join Services s on s.ID = u.Service where u.Username='".$_SESSION["username"]."'";
$result = mysql_query($query) or die ("SQL Error".mysql_error());
$row=mysql_fetch_assoc($result);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Realivent.com - Edit User account</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="listing_panel_css.css">
<script type="text/javascript" src="ajax_get_service.js"></script>
<script>
function show_services()
{
	var str = "<table width=100%><TR><TD><div>What is your service area:<select onChange='get_service(<?php echo $_SESSION['id'] ?>)' name='service' id=service><option value=''> --choose--</option>"

				<?php 
				$ssql = "Select * from Services where Parent_ID = 0 order by Service";
				$sresult = mysql_query($ssql) or die ("SQL Error".mysql_error());
				while($srow=mysql_fetch_assoc($sresult))
				{
					?>
	str = str + "<option value=<?php echo $srow['ID'] ?>><?php echo $srow['Service'] ?></option>"
					<?
				}

				?>
	str = str+"</select></div><div style='padding-left:0px;' id=sub_service>Sub-category: <select name='service'></select></div></TD></TR></table>"
	document.getElementById('show_service').innerHTML = str		
}

function remove_services()
{
	document.getElementById('show_service').innerHTML = ""	
}


</script>
</head>
 
<body>
<center>
<table width="1000" border="0" cellspacing="0" cellpadding="0">
 <TR><TD><?php include('account_header.php'); ?></TD></TR>
  <tr>
    <td valign="top" style="height:300px;">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="200" valign="top" align="left">
	<Div id=menu_column>
      <?php include("menu.php"); ?>
      </Div></td>
    <td width="800" valign="top" align="left" id=main_body>  
	<div><img src=../images/view.jpg align="absmiddle"> <a href=../user_profile.php?id=<?php echo $_SESSION['id'] ?>>View your profile</a></div>
	
	<div id="invertedtabsline">&nbsp;</div>
	<?php include('user_menu_control.php'); ?>
	<BR><BR>
	  <form action="update_user.php" method="post" enctype="application/x-www-form-urlencoded" name="detail_from">
	  <table width="100%" border="0" cellspacing="0" cellpadding="0">
	  	
		 <TR>
			 <TD>
			   <table width="100%" border="0" cellspacing="0" cellpadding="3">
				   <tr>
				   <TD colspan="3">
				   <div style="padding-top:10px;" id=product_header><strong>Personal details:</strong>
				   </TD>
				   </tr>
				   <TR>
				<td valign="top" nowrap="nowrap" align="right">First Name:</td>
				 <TD><input name="firstname" type="text" id="firstname"  value="<?php echo $row["First_Name"]; ?>"  /></TD>
				<TD>
				</td>
				</tr>
				<TR>
				<TD nowrap="nowrap" align="right">
				Last Name: 
				</TD>
				<TD>
				  <input name="lastname" type="text" id="lastname" value="<?php echo $row["Last_Name"]; ?>" />
				 </TD>
				 <TD>
				 </TD>
				 </TR>
				 <TR>
				<TD colspan="3">
				<div><strong>Username:</strong> 
				  <?php echo $row["Username"]; ?>
				 </TD>
				 </TR>
				 <!--
				 <TR>
				 	<TD colspan="3">
						<a href=change_password.php>Change Password</a>
					</TD>
				 </TR>
				 -->
				 <TR>
				 	<TD colspan="3">
					<div style="padding-top:10px;" id=product_header><strong>Business Address:</strong><BR>
					</TD>
				 </TR>
				<tr class="listingsubheading">
                <td align="right" width=110>Street:</td>
                <td align="left"><input name="street" type="text" id="street" class="text"  size="50" value="<?php echo $row["Street"]; ?>" /></td>
                <td align="left">&nbsp;</td>
              </tr>
              <tr class="listingsubheading">
                <td align="right">City:</td>
                <td align="left"><input name="city" type="text" id="city" class="text"  size="50" value="<?php echo $row["City"]; ?>" /></td>
                <td align="left">&nbsp;</td>
              </tr>
              <tr class="listingsubheading">
                <td align="right">State: </td>
                <td align="left"><select name=state id=state>
							<option value="AL">AL</option>
							<option value="AK">AK</option>
							<option value="AZ">AZ</option>
							<option value="AR">AR</option>
							<option value="CA">CA</option>
							<option value="CO">CO</option>
							<option value="CT">CT</option>
							<option value="DE">DE</option>
							<option value="DC">DC</option>
							<option value="FL">FL</option>
							<option value="GA">GA</option>
							<option value="HI">HI</option>
							<option value="ID">ID</option>
							<option value="IL">IL</option>
							<option value="IN">IN</option>
							<option value="IA">IA</option>
							<option value="KS">KS</option>
							<option value="KY">KY</option>
							<option value="LA">LA</option>
							<option value="ME">ME</option>
							<option value="MD">MD</option>
							<option value="MA">MA</option>
							<option value="MI">MI</option>
							<option value="MN">MN</option>
							<option value="MS">MS</option>
							<option value="MO">MO</option>
							<option value="MT">MT</option>
							<option value="NE">NE</option>
							<option value="NV">NV</option>
							<option value="NH">NH</option>
							<option value="NJ">NJ</option>
							<option value="NM">NM</option>
							<option value="NY">NY</option>
							<option value="NC">NC</option>
							<option value="ND">ND</option>
							<option value="OH">OH</option>
							<option value="OK">OK</option>
							<option value="OR">OR</option>
							<option value="PA">PA</option>
							<option value="RI">RI</option>
							<option value="SC">SC</option>
							<option value="SD">SD</option>
							<option value="TN">TN</option>
							<option value="TX">TX</option>
							<option value="UT">UT</option>
							<option value="VT">VT</option>
							<option value="VA">VA</option>
							<option value="WA">WA</option>
							<option value="WV">WV</option>
							<option value="WI">WI</option>
							<option value="WY">WY</option>
						</select>			

				 <script language="JavaScript" type="text/javascript">
				  var cval = "<?php echo $row['State']; ?>";
						for(i=0;i<document.forms[0].state.options.length;i++)
							if(document.forms[0].state.options[i].value==cval)
								document.forms[0].state.options[i].selected=true;
					</script>
									
					  </td>
                <td align="left">&nbsp;</td>
              </tr>
              <tr class="listingsubheading">
                <td align="right">Zip: </td>
                <td align="left"><input name="zip" type="text" id="zip" class="text"  size="20" value="<?php echo $row["Zip"]; ?>" /></td>
                <td align="left">&nbsp;</td>
              </tr>
				</table>
			 
			  
			  <table width="100%" border="0" cellspacing="0" cellpadding="3">
			  <TR>
			  <TD colspan="3"><div style="padding-top:10px;" id=product_header><strong>Contact Information:</strong></div></TD>
			  </TR>
			<tr class="listingsubheading">
                <td align="right" width="110">Email: </td>
                <td align="left"><input name="email" type="text" id="email" class="text" size=50 value="<?php echo $row["Email"]; ?>" /></td>
                <td align="left">&nbsp;</td>
              </tr>
              <tr class="listingsubheading">
                <td align="right">Phone: </td>
                <td align="left"><input name="phone" type="text" id="phone" class="text" size=30 value="<?php echo $row["Phone"]; ?>" /></td>
                <td align="left">&nbsp;</td>
              </tr>
			   <tr class="listingsubheading">
                <td align="right">fax:</td>
                <td align="left"><input name="fax" type="text" id="website" class="text"  size="30" value="<?php echo $row["Fax"]; ?>" /></td>
                <td align="left">&nbsp;</td>
              </tr>
			  
				</table>
				
					<table width="100%" border="0" cellspacing="0" cellpadding="3">
					<TR>
					<TD colspan="3"><div style="padding-top:10px;" id=product_header><strong>Professional Information:</strong></div>
					</TD>
					</TR>
					<TR>
			<TD colspan="2">
				<?php 
				$checked = ($row['Agent'] != 0) ? 'checked' : '';
				?>
				<input name="agent" type="checkbox" value="agent" align="absmiddle" <?php echo $checked ?>> <strong>Other users may contact me if they need my services</strong>
			</TD>
		</TR>
		<TR>
			<TD colspan="2">
				If checked, your user profile will display your occupation, and that people may can contact you for business.<BR>
				
			</TD>
		</TR>
		<TR>
		<TD colspan="2">
		<?php 
	$pquery = "select Service from Services where ID = '".$row['Parent_ID']."'";
	$presult = mysql_query($pquery) or die ("SQL Error".mysql_error());
	$prow=mysql_fetch_assoc($presult);
	
	$str = ($row['Service'] != '') ? "<strong>Service Area:</strong> ".$prow['Service']." - ".$row['Service']. "- <a href=javascript:; onClick='show_services()'>Update</a>" : "<font color=red>Services are not set yet<font> - <a href=javascript:; onClick='show_services()'>Update</a>";
	?>
	<div style="font-size:12px; padding:5px;">
	<?php echo $str ?>
	</div>
	<div id=show_service>
	
	</div>
		
		</TD>
		
		</TR>

					
			<tr class="listingsubheading">
                <td align="right" width=130>Website:</td>
                <td align="left"><input name="website" type="text" id="website" class="text"  size="50" value="<?php echo $row["Website"]; ?>" /></td>
                <td align="left">&nbsp;</td>
              </tr>
			  <tr class="listingsubheading">
                <td align="right" width=130 nowrap="nowrap">Home Search URL:</td>
                <td align="left"><input name="home_search" type="text" id="home_search" class="text"  size="50" value="<?php echo $row["Home_Search_URL"]; ?>" /></td>
                <td align="left">&nbsp;</td>
              </tr>
              <tr class="listingsubheading">
                <td align="right">Company Name / Brokerage:</td>
                <td align="left"><input name="broker" type="text" id="broker" class="text"  size="50" value="<?php echo $row["Brokerage"]; ?>" /></td>
                <td align="left">&nbsp;</td>
              </tr>
			  <tr class="listingsubheading">
                <td align="right">License Number:</td>
                <td align="left"><input name="license" type="text" id="license" class="text"  size="50" value="<?php echo $row["License_Number"]; ?>" /></td>
                <td align="left"></td>
              </tr>
			  <TR>
			  	<TD colspan="3">
					<input name="submit" type="submit" value="Update">
				</TD>
			  </TR>
					</table>


 			</div>
			</form>
			</td>
			<td valign="top" rowspan="2">
			<table style="border:1px dashed #CCCCCC; padding:10px;" border="0" cellspacing="0" cellpadding="0">
				  <tr>
					<td valign="top" align="left" style="padding:5px;">
					<?php 
					if($row['Image'] != '')
					{
					list($width_orig, $height_orig, $image_type) = getimagesize('../user_images/'.$row['Image']);
					$width = 100;
					$ratio = $width/$width_orig;
					$height = $height_orig*$ratio;
					
					?>
					<div style="font-size:10px;padding:5px;">Click on image for full size</div>
					<a href=# onClick="window.open('../user_images/<?php echo $row['Image'] ?>','name','location=no,width=<?php echo $width_orig+20; ?>,height=<?php echo $height_orig+20; ?>');"><img border="0" align="left" width=<?php echo $width; ?> height="<?php echo $height; ?>" src=../user_images/<?php echo $row['Image']; ?> /></a>
					<div style="float:right">
					<?php
					
					echo 'Width= '.$width_orig."px<BR>";
					echo 'Height= '.$height_orig."px<BR>";
					echo "<a href=delete_agent_picture.php>[delete]</a></div>";
					
					} 
					else
					{
					?>
					<img src=../images/blank_agent_image.gif />
					<?
					}
					?>
					
					</td>
					</tr>
					<TR>
					<td valign="top" nowrap="nowrap">
						<form action="add_agent_image.php" method="post" enctype="multipart/form-data" name="photos">
						<input size="10" name="image_file" type="file" />
						<input type=submit value=add>
						</form>
					</td>
				  </tr>
				  <tr>
					<td valign="top" align="left" style="padding:5px;">
					
										<?php 
					if($row['Company_Logo'] != '')
					{
					list($width_orig, $height_orig, $image_type) = getimagesize('../user_images/'.$row['Company_Logo']);
					if($width_orig > 100)
					{
					$width = 100;
					$ratio = $width/$width_orig;
					$height = $height_orig*$ratio;
					}
					else
					{
					$width = $width_orig;
					$height = $height_orig;
					}
					?>
					<div style="font-size:10px;padding:5px;">Click on image for full size</div>
					<a href=# onClick="window.open('../user_images/<?php echo $row['Company_Logo'] ?>','name','location=no,width=<?php echo $width_orig+20; ?>,height=<?php echo $height_orig+20; ?>');"><img border= 0 align="left" width=<?php echo $width; ?> height="<?php echo $height; ?>" src=../user_images/t_<?php echo $row['Company_Logo']; ?> /></a>
					<div style="float:right">
					<?php
					echo 'Width= '.$width_orig."px<BR>";
					echo 'Height= '.$height_orig."px<BR>";
					echo "<a href=delete_agent_logo.php>[delete]</a></div>";
					} 
					else
					{
					?>
					<img src=../images/blank_logo.gif />
					<?
					}
					?>

					</td>
					</tr>
					<TR>
					<td valign="top" nowrap="nowrap">
						<form action="add_agent_logo.php" method="post" enctype="multipart/form-data" name="logos">
						<input size="10" name="image_file" type="file" />
						<input type=submit value=add>
						</form>
					</td>
				  </tr>
				</table>
			</td>
		  </tr>
		</table>



	</td>
  </tr>
 
</table>

		
	</td>
  </tr>
 
</table>
<?php include('../footer.php'); ?>
</body>
</html>
